import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';

export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: '隐患名称',
      dataIndex: 'dangerName',
      fixed: 'left',
      sorter: true,
    },
    {
      title: '隐患描述',
      dataIndex: 'dangerDesc',
    },
    {
      title: '登记时间',
      dataIndex: 'registTime',
      sorter: true,
    },
  ];
}

export function getBasicShortColumns(): BasicColumn[] {
  return [
    {
      title: '隐患名称',
      dataIndex: 'dangerName',
      sorter: true,
      sortOrder: 'ascend',
    },
    {
      title: '隐患描述',
      dataIndex: 'dangerDesc',
    },
    {
      title: '登记时间',
      sorter: true,
      dataIndex: 'registTime',
    },
  ];
}

export function getMultipleHeaderColumns(): BasicColumn[] {
  return [
    {
      title: '隐患名称',
      dataIndex: 'dangerName',
    },
    {
      title: '隐患描述',
      dataIndex: 'dangerDesc',
    },
    {
      title: '登记时间',
      dataIndex: 'registTime',
    },
  ];
}

export function getCustomHeaderColumns(): BasicColumn[] {
  return [
    {
      title: '隐患名称',
      dataIndex: 'dangerName',
    },
    {
      title: '隐患描述',
      dataIndex: 'dangerDesc',
      slots: { title: 'customTitle' },
    },
    {
      title: '登记时间',
      dataIndex: 'registTime',
      slots: { title: 'customTitle' },
    },
  ];
}
const renderContent = (filed) => {
  return (record, rowIndex) => {
    const obj: any = {
      children: record[filed],
      attrs: {},
    };
    if (rowIndex === 9) {
      obj.attrs.colSpan = 0;
    }
    return obj;
  };
};
export function getMergeHeaderColumns(): BasicColumn[] {
  return [
    {
      title: '隐患名称',
      dataIndex: 'dangerName',
      customCell: renderContent('dangerName'),
    },
    {
      title: '隐患描述',
      dataIndex: 'dangerDesc',
      customCell: renderContent('dangerDesc'),
    },
    {
      title: '登记时间',
      dataIndex: 'registTime',
      customCell: renderContent('registTime'),
    },
  ];
}
export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => {
  const arr: any = [];
  for (let index = 0; index < itemNumber; index++) {
    arr.push({
      field: `field${index}`,
      label: `字段${index}`,
      component: 'Input',
      colProps: {
        xl: 12,
        xxl: 8,
      },
    });
  }
  return arr;
};
export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      ...getAdvanceSchema(5),
      {
        field: `field11`,
        label: `Slot示例`,
        component: 'Select',
        slot: 'custom',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}
export function getBasicData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
      });
    }
    return arr;
  })();
  return data;
}

export function getTreeTableData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
        children: [
          {
            id: `l2-${index}`,
            name: 'John Brown',
            age: `1${index}`,
            no: `${index + 10}`,
            address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
            beginTime: new Date().toLocaleString(),
            endTime: new Date().toLocaleString(),
          },
          {
            id: `l3-${index}`,
            name: 'John Mary',
            age: `1${index}`,
            no: `${index + 10}`,
            address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
            beginTime: new Date().toLocaleString(),
            endTime: new Date().toLocaleString(),
          },
        ],
      });
    }
    return arr;
  })();

  return data;
}
